<template>
  <div id="header">
    <span id="header-span1" @click="fanhui()"
      ><img src="img/YZC/xiangzuo.png" class="xiangzuo"
    /></span>
    <div id="header-div">
      <img src="img/YZC/ss.png" id="header-div-img" />
      <input
        type="text"
        id="header-div-inp"
        value=""
        placeholder="请输入关键词"
        v-model="hot"
      />
    </div>
    <span id="header-span2">
      <a href="#" id="header-span2-a" @click="add">搜索</a>
    </span>
    <!-- 隐藏部分 -->
    <ul id="header-ul">
      <li id="header-li" v-for="(sou, index) in getsous" :key="index" v-show="hot!=''" @click="fun(sou.id)">
        <p id="header-p">{{ sou.name }}</p>
        <span id="header-span">约{{ sou.id }}个商品</span>
      </li>
    </ul>
  </div>
</template>

<script type="text/javascript">
import axios from "axios";

export default {
  data() {
    return {
      hot: "",
      sous: [],
    };
  },
  computed: {
    getsous() {
      return this.sous.filter((item) => item.name.indexOf(this.hot) > -1);
    },
  },
  created() {
    axios.get("/xiangqing").then((res) => {
      this.sous = res.data;
      console.log(this.sous);
    });
  },
  methods: {
    add() {
      this.$root.hotgoods.push(this.hot);
      this.hot = "";
    },
    fun(good){
      console.log(good);
      this.$router.push({path: "/list",query:{id:good}});
    },
    fanhui() {
      this.$router.back();
    },
  },
};
</script>

<style scoped>
#header {
  width: 100%;
  height: 0.5rem;
  background-color: #ff6600;
  padding-top: 0.07rem;
  box-sizing: border-box;
  position: fixed;
  top: 0;
}
#header-span1 {
  display: inline-block;
  width: 0.42rem;
  text-align: center;
}
.xiangzuo {
  width: 0.2rem;
  height: 0.22rem;
  margin-top: 0.08rem;
  vertical-align: bottom;
}
#header-div {
  width: 3.23rem;
  height: 0.35rem;
  background-color: white;
  display: inline-block;
  border-radius: 0.05rem;
}
#header-div-img {
  width: 0.18rem;
  height: 0.18rem;
  margin-top: 0.07rem;
  margin-left: 0.05rem;
  vertical-align: top;
  display: inline-block;
}
#header-div-inp {
  width: 3rem;
  height: 0.35rem;
  outline: none;
  border: none;
  text-indent: 0.05rem;
  border-radius: 0.05rem;
}
#header-span2-a {
  font-size: 0.16rem;
  color: white;
  text-decoration: none;
  display: inline-block;
  text-indent: 0.08rem;
}
/* 隐藏部分 */
#header-ul {
  width: 100%;
  background-color: white;
  list-style: none;
  position: fixed;
  top: 0.99rem;
}
#header-li {
  width: 100%;
  height: 0.46rem;
  padding: 0 0.1rem;
  box-sizing: border-box;
  border-bottom: 1px solid #cccccc;
  background-color: white;
  z-index: 999;
}
#header-p {
  float: left;
  font-size: 0.14rem;
  color: #353535;
  line-height: 0.46rem;
}
#header-span {
  float: right;
  font-size: 0.13rem;
  color: #cccccc;
  line-height: 0.46rem;
}
</style>